Java: most efficient way to defensively copy an int[]?

Posted by Jason S on Stack Overflow See other posts from Stack Overflow or by Jason S
Published on 2010-05-13T21:29:53Z Indexed on 2010/05/13 21:34 UTC
Read the original article Hit count: 180

Filed under:
|

I have an interface DataSeries with a method

int[] getRawData();

For various reasons (primarily because I'm using this with MATLAB, and MATLAB handles int[] well) I need to return an array rather than a List.

I don't want my implementing classes to return the int[] array because it is mutable. What is the most efficient way to copy an int[] array (sizes in the 1000-1000000 length range) ? Is it clone()?

© Stack Overflow or respective owner

Related posts about java

Related posts about arrays